package com.itydl.a05;

import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.SeekBar;

import com.itydl.a05.view.RefreshFirstStepView;
import com.itydl.a05.view.RefreshSecondStepView;
import com.itydl.a05.view.RefreshThirdStepView;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";

    private SeekBar mSeekBar;
    private RefreshFirstStepView mStepView;
    private RefreshSecondStepView mSecondView;
    private RefreshThirdStepView mThreeView;
    private AnimationDrawable secondAnim;
    private AnimationDrawable mThreeAnim;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mSeekBar = (SeekBar) findViewById(R.id.sb);
        mStepView = (RefreshFirstStepView) findViewById(R.id.lv_first);
        mSecondView = (RefreshSecondStepView) findViewById(R.id.lv_second);
        mThreeView = (RefreshThirdStepView) findViewById(R.id.lv_three);

        mSecondView.setBackgroundResource(R.drawable.pull_to_refresh_second_anim);
        secondAnim = (AnimationDrawable) mSecondView.getBackground();
        findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //启动
                secondAnim.start();
            }
        });

        mThreeView.setBackgroundResource(R.drawable.pull_to_refresh_third_anim);
        mThreeAnim = (AnimationDrawable) mThreeView.getBackground();
        findViewById(R.id.btn2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //启动
                mThreeAnim.start();
            }
        });

        mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
//                Log.e(TAG,progress+"");
                float currentProgress = (float) progress / (float) seekBar.getMax();
                mStepView.setProgress(currentProgress);
                mStepView.postInvalidate();//重绘-->该控件的onDraw就会被重新调用
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
    }
}
